Skip to content

Add authentication to the queue - #86

Merged
jacob-williamson merged 24 commits into
mainfrom
2_auth
Aug 18, 2026
Merged

Add authentication to the queue#86
jacob-williamson merged 24 commits into
mainfrom
2_auth

Conversation

@jacob-williamson

@jacob-williamson jacob-williamson commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2

Adds authentication to the queue. Another ticket should be created to improve authorisation, taking account what visits users have access to etc. For now we just have a whitelist of approved fedIDs.

  • If no OIDC config is provided, the queue will not authenticate users.
  • If no whitelist is provided in config, anyone who has authenticated can use any endpoint.
  • Providing a whitelist with no OIDC config doesn't make much sense and the whitelist wouldn't be used.

The user who queued a task is now also added to the task object, so this can now be displayed in the UI.

Instructions on how to test:

  • Start up a local queue with config that adds authentication: daq-queuing-service --config tests/system_tests/config_with_auth.yaml -p 8001 --dev
  • Go to the docs page
  • Confirm you can't use any of the endpoints other than healthz and get_queue_state, and the message not authenticated is returned
  • Retrieve a valid token:
  • Click the authorise button in the docs page, paste in the token
  • Confirm the endpoints now work

Testing authorisation:

  • Go to tests/system_tests/config_with_auth.yaml
  • Add the following at the bottom of the file:
authorisation_whitelist:
  - "somebody"
  • Restart the local queue and try the endpoints
  • Confirm that for any endpoints other than get_config, you get a not authorised error.
  • Add your fed ID to the authorisation_whitelist
  • Restart the queue and confirm you can now use all the endpoints

@jacob-williamson
jacob-williamson marked this pull request as draft August 12, 2026 08:59
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.87%. Comparing base (a500c9b) to head (3ef052f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   98.75%   98.87%   +0.11%     
==========================================
  Files          18       20       +2     
  Lines         886      976      +90     
==========================================
+ Hits          875      965      +90     
  Misses         11       11              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jacob-williamson
jacob-williamson marked this pull request as ready for review August 14, 2026 11:51

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you! Couple of questions/suggestions but none of them blockers

authorised = [Depends(whitelist_check)] if whitelist_check else None
router = APIRouter()

@router.get("/config")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could: Why is this not locked down? I'm not sure if it should be or not but it's odd to be left out

@jacob-williamson jacob-williamson Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that if someone was locked out they could get config to see if their fedid was in the whitelist (and see who to ask about it). But not really sure either way, happy to change it.

router = APIRouter()

@router.get("/config")
def get_config() -> AppConfig:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should: Maybe depends on the decision about config being locked or not but it would be good to make it the default that all these routes are locked down:

    router = APIRouter(dependencies=authorised)
    ...
    @router.patch("/queue/state")

This means you're less likely to get the situation where someone adds a route in here thinking it's protected and forgetting to add the dependency

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I'll just lock down get_config and then can apply it to the whole router

async def test_add_tasks_to_queue_adds_user_to_task_object(
app: FastAPI, task_queue_with_history: TaskQueue
):
user = User(fedid="abc12345", email="joe.blogs@diamond.ac.uk", name="Joe Blogs")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must: It's actually Joe Bloggs https://en.wiktionary.org/wiki/Joe_Bloggs, instant PR rejection...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I was appeasing my spell checker, forgetting that blog is a word not a name

@jacob-williamson
jacob-williamson enabled auto-merge (squash) August 18, 2026 16:17
@jacob-williamson
jacob-williamson merged commit b8229c6 into main Aug 18, 2026
9 checks passed
@jacob-williamson
jacob-williamson deleted the 2_auth branch August 18, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add auth to the queuing service

2 participants